#include<bits/stdc++.h>
#define sd(n) scanf("%d",&n) 
#define sld(n) scanf("%lld",&n)
#define pd(n) printf("%d", (n))
#define pld(n) printf("%lld", n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
const int N = 2e5;
#define INF 0x7fffffff
typedef long long int ll;
using namespace std;
//----------------------------------------------------------------------------//
struct CountVal
{
	bool operator()(const char l, const char r)
	{
		return l < r;
	}
};
void solve()
{
	int n;
	sd(n);
	string s, s2;
	cin >> s;
	s2 = s;

	sort(s.begin(), s.end(), CountVal());
	int ans =0;
	/*for (int j = 0; j < n; j++)
	{
		for (int i = j+1; i <=n; i++)
		{

			string s3 = s2;
			auto it = s3.begin();
			sort(it + j, it + i, CountVal());
			if (s3 == s)
			{
				ans = min(ans, i - j);
			}
		}

	}*/

	for (int i = 0; i < n; i++)
	{
		if (s[i] != s2[i])
			ans++;
	}
	pd(ans);
	puts("");

}

int main()
{
	int T;
	sd(T);
	while (T--)
	{
		solve();
	}
	return 0;
}